#include <stdio.h>

#include "Output.h"
#include "Token.h"
#include "../Puffer/Buffer.h"

// writes formatted token content with buffer on disk
char buffer[100];
void output(Buffer &writeBuffer, Token &token) {
	writeBuffer.writeString("Token ");

	static TokenType tt;
	tt = token.getType();
	switch (tt) {
	case IDENTIFIER:
		writeBuffer.writeString("Identifier\t");
		break;
	case RESERVED_WORD:
		writeBuffer.writeString("Reserved Word\t");
		break;
	case ERROR:
		writeBuffer.writeString("Error\t\t");
		break;
	case SIGN:
		writeBuffer.writeString("Sign\t\t");
		break;
	case SIGN_AND:
		writeBuffer.writeString("And\t\t");
		break;
	case SIGN_ASSIGN:
		writeBuffer.writeString("Assign\t\t");
		break;
	case SIGN_CLOSEBRACE:
		writeBuffer.writeString("Close Brace\t");
		break;
	case SIGN_CLOSEBRACKET:
		writeBuffer.writeString("Close Bracket\t");
		break;
	case SIGN_CLOSEPAREN:
		writeBuffer.writeString("Close Paren\t");
		break;
	case SIGN_DIV:
		writeBuffer.writeString("Div\t\t");
		break;
	case SIGN_EQUAL:
		writeBuffer.writeString("Equal\t\t");
		break;
	case SIGN_GREATER:
		writeBuffer.writeString("Greater\t\t");
		break;
	case SIGN_MINUS:
		writeBuffer.writeString("Minus\t\t");
		break;
	case SIGN_MULTI:
		writeBuffer.writeString("Multi\t\t");
		break;
	case SIGN_NOT:
		writeBuffer.writeString("Not\t\t");
		break;
	case SIGN_OPENBRACE:
		writeBuffer.writeString("Open Brace\t");
		break;
	case SIGN_OPENBRACKET:
		writeBuffer.writeString("Open Bracket\t");
		break;
	case SIGN_OPENPAREN:
		writeBuffer.writeString("Open Paren\t");
		break;
	case SIGN_PLUS:
		writeBuffer.writeString("Plus\t\t");
		break;
	case SIGN_SEMICOLON:
		writeBuffer.writeString("Semicolon\t\t");
		break;
	case SIGN_SMALLER:
		writeBuffer.writeString("Smaller\t\t");
		break;
	case COMMENT:
		writeBuffer.writeString("Comment\t\t");
		break;
	case END_OF_FILE:
		writeBuffer.writeString("End of file\t");
		break;
	case INTEGER:
		writeBuffer.writeString("Integer\t\t");
		break;
	default:
		writeBuffer.writeString("Unknown\t\t");
		break;
	}

	writeBuffer.writeString("Line: ");
	sprintf(buffer, "%d\t", token.getLine());
	writeBuffer.writeString(buffer);

	writeBuffer.writeString("Column: ");
	sprintf(buffer, "%d\t", token.getColumn());
	writeBuffer.writeString(buffer);

	if (tt == IDENTIFIER || tt == COMMENT || tt == ERROR) {
		writeBuffer.writeString("Lexem: ");
		writeBuffer.writeString(&token.getLexem()[1]);
		writeBuffer.writeString("\t");
	} else {
		switch (tt) {
		case SIGN_ASSIGN:
			writeBuffer.writeString("Lexem: =\t");
			break;
		case SIGN_AND:
			writeBuffer.writeString("Lexem: &\t");
			break;
		case SIGN_CLOSEBRACE:
			writeBuffer.writeString("Lexem: }\t");
			break;
		case SIGN_CLOSEBRACKET:
			writeBuffer.writeString("Lexem: ]\t");
			break;
		case SIGN_CLOSEPAREN:
			writeBuffer.writeString("Lexem: )\t");
			break;
		case SIGN_DIV:
			writeBuffer.writeString("Lexem: /\t");
			break;
		case SIGN_EQUAL:
			writeBuffer.writeString("Lexem: <=>\t");
			break;
		case SIGN_GREATER:
			writeBuffer.writeString("Lexem: >\t");
			break;
		case SIGN_MINUS:
			writeBuffer.writeString("Lexem: -\t");
			break;
		case SIGN_MULTI:
			writeBuffer.writeString("Lexem: *\t");
			break;
		case SIGN_NOT:
			writeBuffer.writeString("Lexem: !\t");
			break;
		case SIGN_OPENBRACE:
			writeBuffer.writeString("Lexem: {\t");
			break;
		case SIGN_OPENBRACKET:
			writeBuffer.writeString("Lexem: [\t");
			break;
		case SIGN_OPENPAREN:
			writeBuffer.writeString("Lexem: (\t");
			break;
		case SIGN_PLUS:
			writeBuffer.writeString("Lexem: +\t");
			break;
		case SIGN_SEMICOLON:
			writeBuffer.writeString("Lexem: ;\t");
			break;
		case SIGN_SMALLER:
			writeBuffer.writeString("Lexem: <\t");
			break;
		case INTEGER:
			break;
		default:
			writeBuffer.writeString("\t\t");
			break;
		}
	}

	if (tt == INTEGER) {
		writeBuffer.writeString("Value: ");
		sprintf(buffer, "%d\n", token.getValue());
		writeBuffer.writeString(buffer);
	} else {
		writeBuffer.writeString("\n");
	}
}
